package cn.echogo.framework.location;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

public class EGItemizedOverlay extends ItemizedOverlay<OverlayItem> {

	private Context context;
	private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();

	public EGItemizedOverlay(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
	}

	public EGItemizedOverlay(Drawable defaultMarker, Context context) {
		this(defaultMarker);
		this.context = context;
	}

	@Override
	protected OverlayItem createItem(int i) {
		return overlayItemList.get(i);
	}

	@Override
	public int size() {
		return overlayItemList.size();
	}

	@Override
	protected boolean onTap(int index) {
		OverlayItem item = overlayItemList.get(index);
		GeoPoint geoPoint = item.getPoint();
		Address address = LocationUtil.getAddressByGeoPoint(context, geoPoint);
		String addressStr = LocationUtil.getAddressString(address);
		Toast.makeText(context, addressStr, Toast.LENGTH_SHORT).show();
		return true;
	}

	public void addOverlayItem(OverlayItem overlayItem) {
		overlayItemList.add(overlayItem);
		this.populate();
	}

}
